package com.develop.skwen.electricgomall.category.list;

import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.develop.skwen.basemodule.list.BaseAdapter;
import com.develop.skwen.basemodule.list.BaseHolder;
import com.develop.skwen.basemodule.list.BaseItemClickListener;
import com.develop.skwen.electricgomall.R;
import com.develop.skwen.electricgomall.category.list.holder.CategoryHolder;
import com.develop.skwen.electricgomall.category.model.CategoryBean;

import java.util.List;

/**
 * Created by skwen on 2018/6/24.
 */

public class CategoryListAdapter extends BaseAdapter<CategoryBean> {

    private SparseBooleanArray sparseBooleanArray = new SparseBooleanArray();

    private List<CategoryBean> list;

    public CategoryListAdapter(List<CategoryBean> list) {
        super(list);
        this.list = list;
    }

    @Override
    protected BaseHolder getViewHolder(LayoutInflater inflater, ViewGroup parent, int viewType) {
        BaseHolder holder = new CategoryHolder(inflater.inflate(R.layout.category_list_item_layout,parent,false));
        return holder;
    }

    @Override
    protected void onBindHolder(BaseHolder holder, int position) {
        super.onBindHolder(holder, position);
        if (sparseBooleanArray.get(position)){
            holder.itemView.setBackgroundColor(holder.itemView.getContext().getResources().getColor(R.color.category_list_item_white_bg));
        } else {
            holder.itemView.setBackgroundColor(holder.itemView.getContext().getResources().getColor(R.color.category_list_item_bg));
        }
    }

    public void setSelectPosition(int position){
        CategoryBean item = list.get(position);
        if (item != null){
            sparseBooleanArray.clear();
            sparseBooleanArray.put(position,true);
        }
        notifyDataSetChanged();
    }


}
